<!--
 * @Descripttion: 充值订单
 * @Author: xiao li
 * @Date: 2020-11-24 10:08:25
 * @LastEditors: xiao li
 * @LastEditTime: 2020-12-08 14:48:09
-->
<template>
    <div>
        <top-nav :isBack="true"></top-nav>
        <div class="page-main">
          <div class="page-search-form">
            <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
              <el-form-item label="活动名" prop="title">
                <el-input placeholder="请输入活动名" v-model="searchForm.title"></el-input>
              </el-form-item>
              <el-form-item>
                <lb-button size="medium" type="primary"  icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)" >{{$t('action.search')}}</lb-button>
                <lb-button size='medium' icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')" >{{$t('action.reset')}}</lb-button>
              </el-form-item>
            </el-form>
          </div>

          <el-table
              v-loading='loading'
              :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
              style="width: 100%">
                <el-table-column
                  prop="title"
                  label="活动名称">
                </el-table-column>
                <el-table-column
                  prop="num"
                  label="活动名额">
                </el-table-column>
                <el-table-column
                  prop="cash"
                  label="人均金额">
                </el-table-column>
                <el-table-column
                  prop="total_cash"
                  label="充值总金额">
                </el-table-column>
                <el-table-column
                  label="充值时间">
                  <template slot-scope="scope">
                      <p>{{scope.row.create_time | handleTime(1)}}</p>
                      <p>{{scope.row.create_time | handleTime(2)}}</p>
                  </template>
                </el-table-column>
          </el-table>
          <lb-page
            :batch='false'
            :page='searchForm.page'
            :pageSize='searchForm.limit'
            :total='total'
            @handleSizeChange='handleSizeChange'
            @handleCurrentChange='handleCurrentChange'
            >
          </lb-page>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      loading: false,
      searchForm: {
        page: 1,
        limit: 10,
        store_id: 0,
        title: ''
      },
      tableData: [],
      page: 1,
      limit: 10,
      total: 0,
      centerDialogVisible: false,
      dialogForm: {
        title: '',
        top: 0,
        id: ''
      },
      dialogFormRules: {
        title: {required: true, type: 'string', message: '请输入标题', trigger: 'blur'},
        top: {required: true, type: 'number', message: '请输入排序值', trigger: 'blur'}
      }
    }
  },
  created () {
    let {id} = this.$route.query
    this.searchForm.store_id = id
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      this.$api.overlordOrderStoreOrder(this.searchForm).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
        }
      })
    },
    updateActivityInfo (id, status) {
      this.$api.updateActivityInfo({id, status}).then(res => {
        if (res.code === 200) {
          this.$message.success(this.$t('tips.successOper'))
        } else {
          this.getTableDataList()
        }
      })
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.el-select,
.el-input{
  width: 200px;
}
</style>
